/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cheapflix.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.log4j.Logger;

/**
 * Bean class that holds all information
 * pertinent to a user.
 * @author Group B
 */
public class User implements Serializable {

    private static final Logger logger = Logger.getLogger(User.class);
    private HashMap<String, User> friends;
    private HashMap<String, List<RecommendedDVD>> recommendedDVDs;
    private HashMap<String, UserDVD> userDVDs;
    private int id;
    private String email;
    private String nameFirst;
    private String nameLast;
    private String password;
    private String username;

    @Override
    public String toString() {
        return "email: " + email+", nameFirst: " + nameFirst+", nameLast: " + nameLast+", username: " + username+", friends: " + friends +", recommendedDVDs: " + recommendedDVDs;
    }

    
    public User() {
        friends=new HashMap<String, User>();
        recommendedDVDs=new HashMap<String, List<RecommendedDVD>>();
        userDVDs=new  HashMap<String, UserDVD>();
    }

    public void addFriend(String userId, User friend) 
    {
        friends.put(userId, friend);
        // friends2.add(friend);
    }

    public User getFriend(String key) {
        return friends.get(key);
    }

    public void addUserDVD(String dvdId, UserDVD dvd) {
        userDVDs.put(dvdId, dvd);
    }

    public boolean getDidRecommend(int dvdId, int friend) {
        if (recommendedDVDs.get(dvdId + "") == null) {
            return false;
        }
        List<RecommendedDVD> rlist = recommendedDVDs.get(dvdId + "");
        for (RecommendedDVD rdvd : rlist) {
            if (rdvd.getRecommendeeId() == friend) {
                return true;
            }
        }
        return false;
    }

    public UserDVD getUserDVD(String key) {
        return userDVDs.get(key);
    }

    public void addRecommendedDVD(int dvdId, int recommendee) {
        RecommendedDVD rdvd = new RecommendedDVD();
        rdvd.setDvdId(dvdId);
        rdvd.setRecommendorId(id);
        rdvd.setRecommendeeId(recommendee);
        addRecommendedDVD(dvdId + "", rdvd);
    }

    public void addRecommendedDVD(String dvdId, RecommendedDVD recommendedDVD) {
        if (recommendedDVDs.get(dvdId) == null) {
            List<RecommendedDVD> newlist = new ArrayList<RecommendedDVD>();
            recommendedDVDs.put(dvdId, newlist);
        }

        recommendedDVDs.get(dvdId).add(recommendedDVD);

    }

    public List<RecommendedDVD> getRecommendedDVD(String key) {
        return recommendedDVDs.get(key);
    }

    //Getters and setters
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public HashMap<String, User> getFriends() {
        return friends;
    }

    public void setFriends(HashMap<String, User> friends) {

        this.friends = friends;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNameFirst() {
        return nameFirst;
    }

    public void setNameFirst(String nameFirst) {
        this.nameFirst = nameFirst;
    }

    public String getNameLast() {
        return nameLast;
    }

    public void setNameLast(String nameLast) {
        this.nameLast = nameLast;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public HashMap<String, List< RecommendedDVD>> getRecommendedDVDs() {
        return recommendedDVDs;
    }

    public void setRecommendedDVDs(HashMap<String, List<RecommendedDVD>> recommendedDVDs) {
        this.recommendedDVDs = recommendedDVDs;
    }

    public HashMap<String, UserDVD> getUserDVDs() {
        return userDVDs;
    }

    public void setUserDVDs(HashMap<String, UserDVD> userDVDs) {
        this.userDVDs = userDVDs;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + this.id;
        return hash;
    }
}
